package nlp;

import org.tartarus.snowball.ext.porterStemmer;

public class AuthorNameFilter {
	public static String[] authorNames = { "Andrew Lang", "Charles Kingsley",
			"Charlotte Mary Yonge", "G K Chesterton", "H G Wells",
			"Jacob Abbott", "John Morley", "John Ruskin", "R M Ballantyne",
			"Robert Louis Stevenson", "Samuel Vaknin", "Thomas Carlyle",
			"Thomas Henry Huxley", "William Dean Howells",
      "William Henry Giles Kingston", "Andrew McCallum",
      "Christopher Manning", "Lillian Lee", "Raymond Mooney",
      "Regina Barzilay"};

	public static boolean ContainsAuthorName(String token) {
		if (token.toLowerCase().contains("by ")) {
			return true;
		}
		String[] tokenParts = token.split(" ");
		porterStemmer stemmer = new porterStemmer();
		for (String tokenPart : tokenParts) {
			for (String authorName : authorNames) {
				String[] nameParts = authorName.split(" ");
				for (String namePart : nameParts) {
					stemmer.setCurrent(namePart.toLowerCase());
					stemmer.stem();
					String stemmedName = stemmer.getCurrent();
					stemmer.setCurrent(tokenPart.toLowerCase());
					stemmer.stem();
					String stemmedTokenPart = stemmer.getCurrent();
					if (stemmedName.contains(stemmedTokenPart)
							|| stemmedTokenPart.contains(stemmedName)) {
						return true;
					}
				}
			}
		}
		return false;
	}
}
